Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Start adding structure logging, output to logfmt #427

Closed
wants to merge 2 commits into from

Conversation

karlseguin
Copy link
Contributor

Adds a structured logger with output to logfmt format (which is both human readable and supported by most log ingestors).

Some ideas borrowed from https://github.com/karlseguin/log.zig.

My goal is to give each connection a unique conn_id, and each CDP message a req_id. The logger will get passed into CDP + Browser/Session/Page and even ideally into zig-js-runtime. The goal is to generate logs like:

_time=1739795092929 _level=info _ctx=client_connected conn_id=339494
_time=1739795092392 _level=info _ctx=http_request conn_id=339494 path=/json/version status=200
_time=1739795093001 _level=info _ctx=http_request conn_id=339494 path=/
_time=1739795093450 _level=info _ctx=cdp_request conn_id=339494 req_id=1 method=CSS.enable
...

Every log has a _time, _level and _ctx field. The "context" is just meant to be a unique label - nothing worse than getting a log message and not knowing where it originated (although it isn't a substitute for metrics, group by on _ctx can also be used to detect issues).

If everyone's ok with this, I want to close this PR and re-open it after #422 has been merged with more of the std.log switched over to use this.

@krichprollsch
Copy link
Member

LGTM, the only change I could suggest right now is to format the timestamp in a human friendly format :)

@karlseguin
Copy link
Contributor Author

LGTM, the only change I could suggest right now is to format the timestamp in a human friendly format :)

Agree. The latest version, in Debug, does:

info   | this is the message | 0 | key=value key=value
error | this is anotehr message | 10 |

where the time (0, 10) is the # of milliseconds since the last log.

@karlseguin karlseguin closed this Feb 21, 2025
@karlseguin karlseguin deleted the logging branch February 21, 2025 09:40
@github-actions github-actions bot locked and limited conversation to collaborators Feb 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants